home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------------------------------
-
- File: Simple LDEF.c
-
- Function: LDEF to display text-only lists.
-
- Author(s): Erik C. Thauvin (ravensys@eskimo.com)
-
- Copyright: Copyright (C) 1996 Erik C. Thauvin
- All Rights Reserved.
-
- Source: Based on Steve Falkenburg's SICN LDEF
-
- Notes: If the cell's data is too long, it is truncated
- and an ellipsis is added to it; the textface is
- not automatically condensed.
-
- Version(s):
-
- 02/08/96 1.0
-
-
- History:
-
- 02/07/96 ECT Initial coding.
-
-
- Disclaimer:
-
- This software is provided "as is" without express or implied
- warranties. Permission is granted to use, copy, modify and
- distribute this software, provided this disclaimer and copyright
- are preserved on all copies. This software may not, however, be
- sold or distributed for profit, or included with other software
- which is sold or distributed for profit, without the permission
- of the author.
-
- ----------------------------------------------------------------------------*/
-
-
- /* constants for spacing */
-
- const short kLeftOffset = 2;
- const short kTopOffset = 0;
-
-
- /* the truth is out there! */
-
- pascal void main( short message, Boolean hilited, Rect *cellRect, Cell theCell,
- short dataOffset, short dataLen, ListHandle theList )
- {
- FontInfo fontInfo;
- ListPtr theListPtr;
- Ptr cellData;
- SignedByte hStateList, hStateCells;
- Str255 str;
- short leftDraw,topDraw, maxLen;
- unsigned char hMode;
-
- /* lock and dereference list mgr handles */
-
- hStateList = HGetState((Handle)theList);
- HLock((Handle)theList);
- theListPtr = *theList;
- hStateCells = HGetState((Handle)theListPtr->cells);
- HLock((Handle)theListPtr->cells);
- cellData = *(theListPtr->cells);
-
- switch (message)
- {
- case lInitMsg:
- /* we don't need any initialization */
- break;
-
- case lDrawMsg:
- EraseRect(cellRect);
-
- if (dataLen > 0)
- {
- /* determine starting point for drawing */
-
- leftDraw = cellRect->left + theListPtr->indent.h + kLeftOffset;
- topDraw = cellRect->top + theListPtr->indent.v + kTopOffset;
-
- /* move to the text location */
-
- GetFontInfo(&fontInfo);
- MoveTo(leftDraw, topDraw + fontInfo.ascent);
-
- /* Is the cell's textwidth wider than the list's rectangle? */
-
- if (TextWidth(cellData, dataOffset, dataLen) > (cellRect->right - leftDraw))
- {
- /* copy the cell's data to our string */
-
- maxLen = sizeof(str);
- LGetCell(str+1, &maxLen, theCell, theList);
- *str = maxLen;
-
- /* truncate and append ellipsis to our string, then draw it */
-
- TruncString(cellRect->right - cellRect->left, str, smTruncEnd);
- DrawString(str);
- }
- else
- /* draw the cell's data */
- DrawText(cellData, dataOffset, dataLen);
- }
-
- if (!hilited)
- break;
-
- case lHiliteMsg:
- /* clearing the HiliteMode bit forces the next invert to really */
- /* be a "hilite" mode inversion */
-
- hMode = LMGetHiliteMode();
- BitClr((Ptr)(&hMode), (long)pHiliteBit);
- LMSetHiliteMode(hMode);
- InvertRect(cellRect);
- break;
-
- case lCloseMsg:
- break;
- }
-
- /* restore the handles to their original states */
-
- HSetState((Handle)theListPtr->cells, hStateCells);
- HSetState((Handle)theList, hStateList);
- }
-